package com.freejy.ecommunity.utils;

import net.sf.json.JSONObject;

/**
 * Created by Jerry on 15/4/4.
 */
public class Result <T> {

	private Integer code;
    private String msg;
    private T rst;

    public Result(T rst) {
    	this(ResultCode.SUCCESS, rst);
    }
    
    public Result(ResultCode rstCode) {
    	this(rstCode, null);
    }
    
    public Result(ResultCode rstCode, T rst) {
    	this(rstCode.getValue(), rstCode.getText(), rst);
    }
    
    public Result(Integer code, String msg, T rst) {
        this.code = code;
        this.msg = msg;
        this.rst = rst;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public void setCode(Integer code)
    {
    	this.code = code;
    }
    
    public void setMsg(String msg)
    {
    	this.msg = msg;
    }
    
    public void setRst(T rst)
    {
    	this.rst = rst;
    }
    
    @SuppressWarnings("unchecked")
	public T getRst() {
    	if (rst == null)
		{
			rst = (T) new JSONObject();
		}
        return rst;
    }

}
